//
// ***********************************************
// *    ___________   ___________  __      __    *
// *   |______  __/  /_____  ___/  \ \    / /    *
// *         / /          / /       \ \  / /     *
// *        / /          / /         \ \/ /      *
// *       / /          / /           \  /       *
// *      / /______    / /            / /        *
// *     /________/   /_/            /_/         *
// *                                             *
// ***********************************************
//
//   ViewController.m
//   AnalyzeDemo
//   
//   Created  by mac on 2019/7/4
//   Modified by Tiyon
//   Copyright © 2019 wanmeizty. All rights reserved.
//   

#import "ViewController.h"

#import "AnalyzeSDK.h"

#define ztyRGBHexAlpha(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1]
@interface ViewController ()
@property (strong,nonatomic) UITextField * text;
@property (strong,nonatomic) UITextView * showResultText;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.text = [[UITextField alloc] initWithFrame:CGRectMake(16, 80, self.view.frame.size.width - 32, 40)];
    self.text.placeholder = @"请输入淘口令";
    self.text.backgroundColor = ztyRGBHexAlpha(0xF9F6F5);
    self.text.text = @"￥EcmQY5n4Gq1￥";
    [self.view addSubview:self.text];
    
    UIButton *  btn = [[UIButton alloc] initWithFrame:CGRectMake(80, 140, self.view.frame.size.width - 160, 40)];
    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [btn setTitle:@"开始解析淘口令" forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
    btn.layer.cornerRadius = 20;
    btn.backgroundColor = ztyRGBHexAlpha(0xFF7200);
    [self.view addSubview:btn];
    
    self.showResultText = [[UITextView alloc] initWithFrame:CGRectMake(16, 200, self.view.frame.size.width - 32, self.view.frame.size.height - 260)];
    self.showResultText.backgroundColor = ztyRGBHexAlpha(0xF9F6F5);
    self.showResultText.font = [UIFont systemFontOfSize:15];
    [self.view addSubview:self.showResultText];
    // Do any additional setup after loading the view.
}

-(void)click{
    
    __weak __typeof(self) weakSelf = self;
    [AnalyzeSDK analyze:self.text.text compelete:^(NSString *reslut) {
        dispatch_async(dispatch_get_main_queue(), ^{
            __strong typeof(weakSelf) strongSelf = weakSelf;
            strongSelf.showResultText.text = reslut;
        });
    }];
    
}

@end
